package exception;

import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Immutable;
import roborally.board.Board;
import roborally.itemsonboard.BoardItem;
import roborally.supporting.Position;

/**
 * A runtime exception class. When a object moves to a position that is not valid for
 * the given board, this will be thrown.
 * 
 * @author Molderez Tom, 2de bach Ingenieurswetenschappen Computerwetenschappen-Elektrotechniek and Reniers Jorn, 2de bach Ingenieurswetenschappen Werktuigkunde-Computerwetenschappen
 * @version 2.0
 */
public class IllegalPositionOnBoardException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Creates a new IllegalPositionOnBoardException with the given options.
	 * 
	 * @param positionItem The item that tries to change his position.
	 * @param board The board on with the item is localized.
	 * @param position The position to move towards.
	 * @pre The positionItem may not be null.
	 * 		| positionItem != null
	 * @pre The board may not be null and the board must be the same as the board of this.
	 * 		| board != null && positionItem.getBoard() == board
	 * @pre The position may not be null.
	 * 		| position != null
	 */
	public IllegalPositionOnBoardException(String message, BoardItem positionItem,
			Board board, Position position) {
		super(message);
		assert positionItem != null;
		assert board != null && positionItem.getBoard() == board;
		assert position != null;
		this.positionItem = positionItem;
		this.board = board;
		this.position = position;
	}
	
	/**
	 * Returns the positionItem of this IllegalPositionOnBoardException.
	 */
	@Basic @Immutable
	public BoardItem getPositionItem() {
		return this.positionItem;
	}
	
	/**
	 * The positionItem of this IllegalPositionOnBoardException.
	 */
	private final BoardItem positionItem;
	
	/**
	 * Returns the board of this IllegalPositionOnBoardException.
	 */
	@Basic @Immutable
	public Board getBoard() {
		return this.board;
	}
	
	/**
	 * The board of this IllegalPositionOnBoardException.
	 */
	private final Board board;
	
	/**
	 * Returns the position of this IllegalPositionOnBoardException.
	 */
	@Basic @Immutable
	public Position getPosition() {
		return this.position;
	}
	
	/**
	 * The position of this IllegalPositionOnBoardException.
	 */
	private final Position position;
	
	/**
	 * Returns the message explaining this exception.
	 */
	@Override @Basic @Immutable
	public String getMessage() {
		String message = super.getMessage();
		return message + "\nThe positionItem: " + getPositionItem().toString() + ", The board: " +
				getBoard().toString() + ", The position: " + getPosition().toString();
				
	}

}
